package com.powernode.spring6.service;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Order(2)
public class LogAspect {//切面
    //切面=通知+切点
    //通知就是增强，就是具体的要编写的增强代码
    /*
    @Before("execution(* com.powernode.spring6.service..*(..))")
    public void 增强(){
        System.out.println("我是增强代码...");
    }*/
    @Pointcut("execution(* com.powernode.spring6.service..*(..))")
    public void 通用切点(){

    }
    //前置通知
    @Before("通用切点()")
    public void beforeAdvice(JoinPoint joinPoint){
        System.out.println("前置通知");
        Signature signature = joinPoint.getSignature();//获取目标方法的签名
        System.out.println(signature);
    }
    //后置通知
    @AfterReturning("通用切点()")
    public void afterReturningAdvice(){
        System.out.println("后置通知");
    }
    //环绕通知
    @Around("通用切点()")
    public void aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("前环绕");
        joinPoint.proceed();//执行目标
        System.out.println("后环绕");
    }
    //异常通知
    @AfterThrowing("通用切点()")
    public void afterThrowingAdvice(){
        System.out.println("异常通知");
    }
    //最终通知
    @After("通用切点()")
    public void afterAdvice(){
        System.out.println("最终通知");
    }
}
